package binary_tree.Newcode;

import java.util.Scanner;

public class KY11 {
    private static class TreeNode{
       char val;
       TreeNode left;
       TreeNode right;
        public TreeNode(char val) {
            this.val = val;
        }
    }
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while(scanner.hasNext()){
            String line=scanner.next();
            TreeNode root=build(line);
            inOrder(root);
            System.out.println( );
        }
    }
  private static void inOrder(TreeNode root){
        if(root==null){
            return;
        }
        inOrder(root.left);
      System.out.print(root.val+" ");
      inOrder(root.right);
  }
    private static TreeNode build(String line){
        return preOrderBuild(line);
    }
    static int index=0;
    private static TreeNode preOrderBuild(String line){
        char c=line.charAt(index);
        if(c=='#'){
            return null;
        }
        TreeNode root=new TreeNode(c);
        index++;
        root.left=preOrderBuild(line);
        index++;
        root.right=preOrderBuild(line);
        return root;
    }
}
